package com.qianyu.project.service.handler;

import com.alibaba.fastjson.JSON;
import com.qianyu.project.core.annotation.FlowHandler;
import com.qianyu.project.core.bean.FormAudit;
import com.qianyu.project.core.context.handler.FlowFinishedHandler;
import com.qianyu.project.entity.DeviceCollect;
import com.qianyu.project.entity.DeviceRepair;
import com.qianyu.project.service.IDeviceCollectService;
import com.qianyu.project.service.IDeviceRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author gs
 * @date create in 2021/2/2 5:58
 */
@Component
@FlowHandler("device_repair")
public class DeviceRepairHandler implements FlowFinishedHandler {

    @Autowired
    private IDeviceRepairService deviceRepairService;
    @Override
    public void postAllowHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit , 3);
    }

    @Override
    public void postRefuseHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit , 2);
    }

    /**
     * description: 通用更新的方法 <br/>
     * author: gs   <br/>
     * date: 2021/2/2 <br/>
     * params: [jsonForm, formAudit] <br/>
     * return: void
     */
    private void commonUpdate(String jsonForm,FormAudit formAudit, Integer approveStatus) {
        DeviceRepair deviceRepair = JSON.parseObject(jsonForm, DeviceRepair.class);
        deviceRepair.setApproveStatus(approveStatus+"");
        deviceRepairService.updateById(deviceRepair);
    }
}
